using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.ComponentModel;
using System.Data.SqlClient;

public partial class Login : MyPage
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["us_id"] != null) 
        {
            Response.Redirect("Events.aspx");
            Response.End();
        }
    }

    protected void OnLoginError(object sender, EventArgs e)
    {
        LoginBox.PasswordRecoveryText = "Forgot your password?";
    }

    protected void Authenticate(object sender, AuthenticateEventArgs e)
    {
        SqlCommand sp = new SqlCommand("cm_Login", conn);
            sp.CommandType = CommandType.StoredProcedure;
            sp.Parameters.AddWithValue("@uid", LoginBox.UserName);
            sp.Parameters.AddWithValue("@pass", LoginBox.Password);
        conn.Open();
        if (sp.ExecuteScalar() != null)
        {
            e.Authenticated = true;
            Session["us_id"] = sp.ExecuteScalar();
        }
        conn.Close();
    }
}
